package com.test;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;

import com.group1.model.Lecturer;
import com.group1.model.Subject;
import com.group1.model.Topic;
import com.group1.util.SessionFactoryUtil;

public class testTopic {

	public static void main(String[] args) {
		Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
	//	getLecturer(session);
	//	createTopic(session);
	//	updateTopic(session);
	//	deleteTopic(session);
		getTopic(session);
		session.getTransaction().commit();
	}
	
	
	public static void getTopic(Session session)
	{
		List<Topic> list = Topic.getAllTopic(session);
		//List<Topic> list = Topic.getTopicBySubject("SJ1", session);
		//List<Topic> list = Topic.getTopicByTopTopic(1, session);
		//List<Topic> list = Topic.getTopicOfLecturer("Lecturer1", session);
		//List<Topic> list = new ArrayList<Topic>();
		//list.add(Topic.getTopicByID(1, session));
		for (Topic topic : list) {
			System.out.println("ID: " + topic.topicId + ", Name: " + topic.topicName + 
					", topTopic: " + topic.topTopic + ", SubjectID: " + 
					topic.subject.subjectId + ", Lecturer: " + topic.lecturer.lecturerId);
		}
	}
	
	public static void getLecturer(Session session)
	{
		List<Lecturer> list = Lecturer.getAllLecturer(session);
		//List<Topic> list = Topic.getTopicBySubject("SJ1", session);
		//List<Topic> list = Topic.getTopicByTopTopic(1, session);
		//List<Topic> list = Topic.getTopicOfLecturer("Lecturer1", session);
		//List<Topic> list = new ArrayList<Topic>();
		//list.add(Topic.getTopicByID(1, session));
		for (Lecturer lecturer : list) {
			System.out.println("ID: " + lecturer.lecturerId + ",  name: " + lecturer.lecturerName);
		}
	}
		
	
	public static void createTopic(Session session)
	{
		Topic t = new Topic();
		t.setTopicName("NewTopicName");
		t.setTopicNote("NewNote");
		t.setTopTopic(1);
		t.setSubject(Subject.getSubjectByID("SJ2", session));
		//t.lecturer = Lecturer.getLecturerById("LectureID1", session);
		t.setLecturer(Lecturer.getLecturerById("LectureID2", session));
		System.out.println("LecturerID: " + t.lecturer.lecturerId);
		session.save(t);
	}
	
	public static void updateTopic(Session session)
	{
		Topic t = Topic.getTopicByID(21, session);
		t.topicNote = "Updated Note";
		session.saveOrUpdate(t);
		
	}
	
	public static void deleteTopic(Session session)
	{
		session.delete(Topic.getTopicByID(21, session));
	}
}
